package com.example.newapplication.SealFragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.newapplication.Bean.Abnormal;
import com.example.newapplication.Fragment.HeadFragment;
import com.example.newapplication.R;

import java.util.ArrayList;
import java.util.List;


public class BuyFragment extends Fragment {

    private RecyclerView recyclerView;
    private List<Abnormal> list;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_buy, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = getActivity().findViewById(R.id.recycler_buy);
        list = new ArrayList<>();
        if(list!=null){
            list.clear();
        }
        for(int i=0;i<8;i++){
            Abnormal abnormal = new Abnormal();
            abnormal.equipmentName = "Apple iPhone " + i + " Pro";
            abnormal.equipmentNum = "100861" + i;
            abnormal.userName = "徐小坚 " + i +" 号";
            abnormal.userNum = "2018010225";
            list.add(abnormal);
        }
        recyclerView.addItemDecoration(new HeadFragment.SpacesItemDecoration(10));
        recyclerView.setAdapter(new mAdapter());
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    }
    class mAdapter extends RecyclerView.Adapter<mViewHolder>{

        @NonNull
        @Override
        public mViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.item4,parent,false);
            mViewHolder mviewHolder = new mViewHolder(view);
            return mviewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull mViewHolder holder, int position) {
            holder.id.setText(list.get(position).equipmentNum);
            holder.name.setText(list.get(position).equipmentName);
            holder.id2.setText(list.get(position).userNum);
            holder.name2.setText(list.get(position).userName);
        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }
    class mViewHolder extends RecyclerView.ViewHolder {

        TextView id,name,id2,name2;
        public mViewHolder(@NonNull View itemView) {
            super(itemView);
            id = itemView.findViewById(R.id.textView36);
            name = itemView.findViewById(R.id.textView37);
            id2 = itemView.findViewById(R.id.textView34);
            name2 = itemView.findViewById(R.id.textView35);
        }
    }
}